package com.xinxing.learning.security.controller;

import com.xinxing.learning.security.entity.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
public class TestController {

    @GetMapping("/test")
    public String test() {
        log.info("test() called with parameters => {}", "测试请求示例");
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        User principal = (User) authentication.getPrincipal();
        log.info("认证信息: {}", authentication);
        log.info("身份信息: {}", principal.getUsername());
        log.info("权限信息: {}", authentication.getAuthorities());
        return "security split test => " + principal.getUsername();
    }
}
